#include <mqueue.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <sys/stat.h>
#include <iostream>
using namespace std;

#define FILE_MODE S_IRUSR|S_IWUSR

struct mq_attr attr;

int main(int argc, char** argv){
    int c, flags;
    mqd_t mqd;
    flags = O_RDWR|O_CREAT;
    
    while( ( c = getopt(argc, argv, "e" ) ) != -1 ){
        switch (c){
        case 'e':
            flags |= O_EXCL;
            break;
        }
    }
    
    if( optind != argc - 1 ){
        printf("usage: mqcreate [ -e ]  <name>\n");
        return  -1;
    }

    mqd = mq_open( argv[optind], flags, FILE_MODE, NULL);
    printf("The message queue d: %d \n", mqd);
    if(mqd < 0){
        printf("%d :%s \n", errno, strerror(errno));
        return -1;
    }
    
    mq_close(mqd);
    exit(0);
}
    


